package com.yunfangdata.service.impl;

import com.yunfangdata.domain.Refund;
import com.yunfangdata.mapper.RefundMapper;
import com.yunfangdata.query.RefundQueryObject;
import com.yunfangdata.service.IRefundService;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RefundServiceImpl implements IRefundService {

    @Autowired
    private RefundMapper mapper ;
    @Override
    public void save(Refund entity) {
        mapper.insert(entity);
    }

    @Override
    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Refund entity) {
        mapper.updateByPrimaryKey(entity);
    }

    @Override
    public Refund get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Refund> list() {
        return mapper.selectAll();
    }

    @Override
    public PageResult query(RefundQueryObject qo) {
        int total = mapper.queryForCount(qo);

        if (total == 0){
            return new PageResult();
        }
        List<Refund> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    @Override
    public void changeState(Long id) {
        mapper.changeState(id);
    }

}